from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from createFreeExcel import create_Free_template
from 自动化流程测试.招募结算一体流程.reClick import click_element

url = 'http://192.168.0.220/#/login'


def run_automation_flow(username,password,pay_password,url,dept_name,type):
    print('开始执行招募，结算，支付自动化流程')
    # 启动浏览器驱动
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(10)
    # 访问url
    driver.get(url)

    # 定位元素，执行自动化操作--填充账号信息
    sleep(1)
    click_element(driver,'NAME',1,'username',f'填充账号{username}',username)

    # 执行自动化操作--填充密码信息
    sleep(1)
    click_element(driver,'NAME',1,'password',f'填充密码{password}',password)

    #定位验证码，验证码已取消，填充默认值
    sleep(1)
    driver.find_element(By.NAME, 'code').send_keys('1234')

    #登录点击事件
    click_element(driver,'XPATH',1,'//*[@id="pane-bindLogin"]/button','登录点击事件',None)

    sleep(1)
    click_element(driver,'XPATH',1,'//*[@id="app"]/div/div[1]/div[2]/div[1]/div/ul/div[3]/li/div','点击展开定向招募菜单',None)

    sleep(1)
    click_element(driver,'XPATH',1,'//*[@id="app"]/div/div[1]/div[2]/div[1]/div/ul/div[3]/li/ul/div/a','点击定向招募',None)

    sleep(1)
    click_element(driver,'XPATH',1,'//*[@id="app"]/div/div[2]/section/div[2]/div[1]/div[2]/div/form/div/div[5]/div[2]/table/tbody/tr[1]/td[11]/div/button[2]','点击招募按钮',None)

    sleep(1)
    click_element(driver,'XPATH',1,'//*[@id="app"]/div/div[2]/section/div[2]/div[2]/div[2]/div[1]/div/div/div[1]/button[1]','点击批量招募',None)

    free_excel_path = create_Free_template(dept_name)
    driver.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/section/div[2]/div[4]/div[1]/div/div[2]/div[1]/div/div/input').send_keys(free_excel_path)

    click_element(driver,'XPATH',1,'//*[@id="app"]/div/div[2]/section/div[2]/div[4]/div[1]/div/div[2]/div[3]/span/button[2]','确认招募',None)
    sleep(10)
    driver.quit()

run_automation_flow('lc0055','147258369','147258369',url,'测试部门','1')